﻿@model IEnumerable<ElectrosLTD.Models.ShoppingCartModel>

@{
    ViewBag.Title = "ShoppingCart";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script type="text/javascript">

    function Purchase() {
        $('#btnPurchase').click(function () {
            $.post("/Product/PurchaseItems")
            alert("Items purchased!")
        })
    }

    function OnSuccess() {
        alert("Success");
    }
</script>


<h2>ShoppingCart</h2>

<table>
    <tr>
        <th>
            productId
        </th>
        <th>
            productName
        </th>
        <th>
            Image
        </th>
        <th>
            Stock
        </th>
        <th>
            Price
        </th>        
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.productId)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.productName)
        </td>
        <td>
           <img src="@Html.DisplayFor(modelItem => item.Image)" alt="" width="100px" height="100px"/>
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Stock)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Price)
        </td>        
        <td>
            @Html.ActionLink("Delete", "DeleteFromCart", "Product", new { id = item.shoppingCartID }, new AjaxOptions() { UpdateTargetId = "table", HttpMethod = "POST", OnSuccess = "OnSuccess", OnComplete = "OnSuccess" })
            @Html.ActionLink("Details", "Details", new { ProductID = item.productId })
        </td>
    </tr>
}

</table>

<fieldset> 
    @Ajax.ActionLink("Purchase Items", "PurchaseItems", "Product", new AjaxOptions() { HttpMethod = "GET", OnSuccess = "OnSuccess();", OnComplete = "OnSuccess" })
</fieldset>